//
//  LGSSelectNodeTypeSheetController.m
//  LogicSim
//
//  Created by Jeremy Pereira on 29/04/2012.
//  Copyright (c) 2013 Jeremy Pereira. All rights reserved.
//

#import "LGSSheetController.h"
#import "LGSSheetDelegate.h"
#import "LGSName.h"

enum  
{
    SHEET_END_OK = 0,
    SHEET_END_CANCEL = 1,
};

@interface LGSSheetController()

-(void) didEndSheet: (NSWindow*) sheet
         returnCode: (NSInteger) returnCode
        contextInfo: (void*) context;
@property (weak) id<LGSSheetDelegate> delegate;

@end

@implementation LGSSheetController

@synthesize sheet, delegate;

-(void) showWithDelegate: (id<LGSSheetDelegate>) newDelegate
{
    [self setDelegate: newDelegate];
    [self setUpUI];
    [NSApp beginSheet: [self sheet]
       modalForWindow: [[self delegate] windowForSheetController: self]
        modalDelegate: self 
       didEndSelector: @selector(didEndSheet:returnCode:contextInfo:)
          contextInfo: NULL];
}

-(void) didEndSheet: (NSWindow*) theSheet
         returnCode: (NSInteger) returnCode
        contextInfo: (void*) context
{
    [theSheet orderOut: self];
    if (returnCode == SHEET_END_OK)
    {
        [self informDelegateOfEndSheet];
    }
    else 
    {
        [[self delegate] sheetCanceled: self];
    }
}

-(IBAction) closeSheet: (id)sender
{
    [NSApp endSheet: [self sheet] returnCode: SHEET_END_OK];
}

-(IBAction) cancelSheet: (id)sender
{
    [NSApp endSheet: [self sheet] returnCode: SHEET_END_CANCEL];
}

-(void) setUpUI
{
}

-(void) informDelegateOfEndSheet
{
}

@end
